package com.controller;

import com.dto.OutGoodsDTO;
import com.entity.OutGoods;
import com.entity.Result;
import com.service.OutGoodsService;
import com.util.CurrentUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: xuan
 * @Date: 2024/7/510:52
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/out")
public class OutGoodsController {
    @Autowired
    private OutGoodsService outGoodsService;
    @Autowired
    private CurrentUser currentUser;
    @RequestMapping("/add")
    public Result outGoods(OutGoods outGoods){
        //出库，查找总数等，相加减，进行出库。
        outGoodsService.outGoods(outGoods);
        return new Result<>(200,"出库成功",null);
    }
    @RequestMapping("/getAll/{pageIndex}/{pageSize}")
    public Result getAll(@RequestBody OutGoods outGoods,
                         @PathVariable("pageIndex") Integer pageIndex,
                         @PathVariable("pageSize") Integer pageSize){
        //分页查询
        log.info("分页查询，当前页数：{}，每页条数：{}，接受值为：{}",pageIndex,pageSize,outGoods);
        return new Result<>(200,"查询成功", outGoodsService.findAll(outGoods,pageIndex, pageSize));
    }
    @RequestMapping("/outgoods")
    public Result outgoods(@RequestBody OutGoods outGoods){
        outGoods.setEid(currentUser.getCurrentEid());

        outGoodsService.outGoods(outGoods);
        return new Result<>(200,"出库成功", null);
    }
}
